package com.ali.ttt.mongo;
import org.bson.BsonDateTime;
import org.bson.BsonTimestamp;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @Author : yuxl
 * @create 2024/7/25 2:11 PM
 */
@ReadingConverter
public class BsonDateTimeToLocalDateTimeConverter implements Converter<BsonDateTime, LocalDateTime> {

    @Override
    public LocalDateTime convert(BsonDateTime source) {
        return LocalDateTime.ofEpochSecond(source.getValue() / 1000, 0, ZoneOffset.UTC);
    }
}
